package com.atguigu.hbase.filter.addition;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.*;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * SkipFilter和valueFilter组合起来获取不包含空列值的行
 */
public class SkipFilterTest {

    public static void main(String[] args) {

        Filter filter = new ValueFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("val-0")));

        Scan scan = new Scan();
        scan.setFilter(filter);
        ResultScanner scanner = table.getScanner(scan);
        for (Result result: scanner) {
            for (KeyValue kv: result.raw()) {
                System.out.println("KV:" + kv + ",value" + Bytes.toString(kv.getValue()));
            }
        }
        scanner.close();

        Filter filter1 = new SkipFilter(filter);
        scan.setFilter(filter1);
        ResultScanner scanner1 = table.getScanner(scan);
        for (Result result: scanner1) {
            for (KeyValue kv : result.raw()) {
                System.out.println("KV:" + kv + ",value" + Bytes.toString(kv.getValue()));
            }
        }
        scanner1.close();
    }
}
